#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
# ----------------------------------------------------------------------------
#  Purpose:     日志输出初始化程序

#  Author:      青衫少年春归也

#  Created:     2020.01.11

# ----------------------------------------------------------------------------
'''

import os
import logging
from datetime import datetime

class MyLog():
    """
    自定义日志记录类
    """
    def mylog(self, name:str="root", log_path:str="."):
        """
        自定义日志对象，名称与验证源对应
        :param log_path: 日志存储目录
        :param name: 日志文件名
        :return: 日志记录对象
        """
        now = datetime.now().strftime("%Y%m%d-%H%M")
        logpath = os.path.join(log_path, "%s.log"%now)
        logger = logging.getLogger(name)
        logger.propagate = False
        logger.setLevel(logging.DEBUG)
        runlog = logging.FileHandler(logpath, 'w')
        runlog.setLevel(logging.DEBUG)
        formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s')
        runlog.setFormatter(formatter)
        logger.addHandler(runlog)
        logger.info(8 * "*" + "  START  " +8 * "*")
        return logger
